const Container = function(val){
  this.value = val
}
let testVal = new Container(3) 
let testObj = new Container({a:1})

Container.of=function(val){
  return new Container(val)
}
const test = Container.of(Container.of(3))

// 定义map函数
Container.prototype.map = function(fn){
  return Container.of(fn(this.value))
}

const db = x => x * 2
let dbVal = Container.of(3).map(db)
// 链式调用
let linkVal = Container.of(4).map(db).map(db).map(db)
// 实现MayBe函子
const MayBe = function(val){
  this.value = val
}
// 取代new的过程
MayBe.of = function(val){
  return new MayBe(val)
}
// 判断传入的值是否为空
MayBe.prototype.isNothing = function(){
  return this.value === null || this.value===undefined
}
// 实现map函数
MayBe.prototype.map = function(fn){
  return this.isNothing(this.value) ? MayBe.of(null) : MayBe.of(fn(this.value))
}

let aaa =MayBe.of('hello').map(x=>x+ ' world').map(e=>e.split(' '))
let bbb = MayBe.of(null).map(x=>x+' world').map(x=>111)
let ccc = MayBe.of(1).map(()=>undefined).map(x=> 222)
let {value} = aaa
